package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺管理
 */
@RestController
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {
    @Autowired
    RedisTemplate redisTemplate;
    public static final String SHOP_STATUS="SHOP_STATUS";

/**
 * 设置状态的方法
 * 该方法用于执行状态设置的相关操作
 *
 * @return 返回一个Result对象，包含操作结果信息
 */
@PutMapping("/{status}")
@ApiOperation("设置店铺营业状态")
    public Result setStatus(@PathVariable Integer status){
    log.info("店铺营业状态：{}",status);
    ValueOperations valueOperations = redisTemplate.opsForValue();
    valueOperations.set(SHOP_STATUS,status);
    return Result.success();
    }
    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态")
    public Result getStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer) valueOperations.get(SHOP_STATUS);
        log.info("店铺营业状态：{}",status);
        return Result.success(status);
    }

}

